import {IListParams, IResponse} from "@/api/types/common";
import request from "@/utils/request";
import {IChatMessage, IClientInfo} from "@/api/types/chat";
import {IUserInfo} from "./types/user";


// 获取在线列表
export const getClientList = (params: IListParams) => {
  return request<IResponse<IClientInfo>>({
    method: 'GET',
    url: '/chat/queryList',
    params
  })
}

// 获取客户端列表
export const getUserList = (name: string) => {
  return request<IClientInfo[]>({
    method: 'GET',
    url: '/chat/getUserList?username=' + name,
  })
}

// 断开连接
export const killId = (id: number) => {
  return request<IResponse<any>>({
    method: 'GET',
    url: '/chat/kill/' + id,
  })
}


// 获取用户信息
export const getChatUser = (username: string) => {
  return request<IUserInfo>({
    method: 'GET',
    url: `/chat/getUser/${username}`,
  })
}

export const sendMessage = (message: IChatMessage) => {
  return request({
    method: 'POST',
    url: `/chat/send`,
    data: message
  })
}
